package com.hmall.item.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;
    @GetMapping("/list")
    public PageDTO<Item> findByPage(@RequestParam Long page,
                                    @RequestParam Long size){
        PageDTO<Item> pageDTO =itemService.findByPage(page,size);
        return pageDTO;
    }
    @GetMapping("/{id}")
    public Item findById(@PathVariable Integer id){
        Item item = itemService.findById(id);
        return item;
    }
    @PostMapping
    public void saveItem(@RequestBody Item item){
        itemService.saveItem(item);
    }
    @PutMapping("/status/{id}/{status}")
    public void updateItemStatus(@PathVariable Integer id,
                       @PathVariable Integer status){
        itemService.updateItemStatus(id,status);
    }
    @PutMapping
    public void updataItem(@RequestBody Item item){
        itemService.updataItem(item);
    }
    @DeleteMapping("/{id}")
    public void deleteItem(@PathVariable Integer id){
        itemService.deleteItem(id);
    }
    @PutMapping("/stock/{itemId}/{num}")
    public void deStock(@PathVariable Long itemId,
                        @PathVariable Integer num){
        itemService.deStock(itemId,num);
    }

}
